// 引入 Vuex 和 createApp 函数
import { createStore } from 'vuex';


// 准备 state - 用于存储数据
const state = {
    SELECTDATASET: "",
    searchNode1: '',
    searchNode2: '',
    dataResult: null, // 添加 dataResult 到 state 中
};

// 准备 mutations - 用于操作数据(state)
const mutations = {
    SELECTDATASET(state,value){
        console.log('mutations中的SELECTDATASET被调用了',state ,value);
        state.SELECTDATASET=value;
    },
    SET_SEARCH_NODE1(state, value) {
        state.searchNode1 = value;
    },
    SET_SEARCH_NODE2(state, value) {
        state.searchNode2 = value;
    },
    SET_DATA_RESULT(state, dataResult) {
        state.dataResult = dataResult;
        console.log(state.dataResult)
      },
};
 
 
// 准备 actions - 用于响应组件中的动作
const actions = {
    selectedDataset(context,value){
        console.log('actions中的selectedDataset被调用了',context ,value);
        context.commit('SELECTDATASET',value);   
    },
    setSearchNode1({ commit }, value) {
        commit('SET_SEARCH_NODE1', value);
    },
    setSearchNode2({ commit }, value) {
        commit('SET_SEARCH_NODE2', value);
    },

};

//创建 store
const store = createStore({
    actions,
    mutations,
    state
});
 
//暴露store
export default store;